/*--------------------------------------------渲染页面--------------*/
function getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

var courseId = getQueryString("id");

$.ajax({
    type: "GET",
    url: "rest/course/find", //根据id查询记录
    data: {
        courseId: courseId
    },
    dataType: "json",
    success: function(data) {
        //获取到id=xxx的用户对象
        var course = data.data;
        $("#id").val(course.id);
        $("#name").val(course.name);
        $("#teacher").val(course.teacher);
        $("#coursenumber").val(course.coursenumber);
        $("#type").val(course.type);
        //给提交按钮绑定事件
        $("#submitBtn").click(function() {
            updateCourse();
        })

    }
});
/*--------------------------------------------渲染页面--------------*/
function updateCourse() {
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "rest/course/update", //更新路径
        data: {
            courseId: $("#id").val(),
            courseName: $("#name").val(),
            courseTeacher: $("#teacher").val(),
            courseNumber: $("#coursenumber").val(),
            courseType: $("#type").val()
        },
        success: function(data) {

            window.location.href = "rest/course/course"; //跳转到列表页面
        }

    });
}
